// Angular Version 6 below need to be deleted {providedIn: 'root'}

// angular
import {Injectable} from '@angular/core';

import {HttpParams} from '@angular/common/http';
// owner
import {Request} from 'pengesoft-ng-lib';
// models
// import {Departments} from '../domains/departments.domain';
// import {any[]} from '../domains/any[].domain';
import {MyDepartment} from '../domains/mydepartment.domain';
// models
import {Department} from '../domains/department.domain';
// @ts-ignore
// import {Department} from 'pengesoft-ng-lib';
import {Departments} from '../domains/departments.domain';
// import {any[]} from '../domains/any[].domain';

/**
 * DeptServiceSvr
 */
@Injectable({
  providedIn: 'root'
})
export class DeptServiceSvr {
  baseUrl: string;

  constructor(
    private request: Request
  ){
    this.baseUrl = 'DeptServiceSvr.assx/';
  }

  /**
   *
   *
   */
  getDepartmentTree(token: string, id: number, option: number): Promise<Department>{
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('id', id.toString())
      .append('option', option.toString());
    return this.request.post<Department>(this.baseUrl + 'getDepartmentTree', httpParams).then((res) => {

      return res;
    });
  }

  /**
   *
   *
   */
  addDepartment(deptName: string, pid: number, leader: string): Promise<number>{
    const httpParams = new HttpParams()
      .append('deptName', deptName.toString())
      .append('pid', pid.toString())
      .append('leader', leader.toString());
    return this.request.post<number>(this.baseUrl + 'addDepartment', httpParams).then((res) => {
      return res;
    });
  }

  /**
   *
   *
   */
  addDept(): Promise<number>{
    const httpParams = new HttpParams();
    return this.request.post<number>(this.baseUrl + 'addDept', httpParams).then((res) => {
      return res;
    });
  }

  /**
   *
   *
   */
  GetVersion(): Promise<string>{
    const httpParams = new HttpParams();
    return this.request.post<string>(this.baseUrl + 'GetVersion', httpParams).then((res) => {
      return res;
    });
  }

  /**
   *
   */
  getAllDepartmentDto(): Promise<any[]>{
    const httpParams = new HttpParams();
    return this.request.post<any[]>(this.baseUrl + 'getAllDepartmentDto', httpParams).then((res) => {
      return res;
    });
  }

  /**
   *
   *
   */
  getDeptCount(deptId: number, state: string): Promise<number>{
    const httpParams = new HttpParams()
      .append('deptId', deptId.toString())
      .append('state', state.toString());
    return this.request.post<number>(this.baseUrl + 'getDeptCount', httpParams).then((res) => {
      return res;
    });
  }

  /**
   *
   */
  getDepartments(): Promise<Department>{
    const httpParams = new HttpParams();
    return this.request.post<Department>(this.baseUrl + 'getDepartments', httpParams).then((res) => {
      return res;
    });
  }

  /**
   *
   */
  getAllMyDepartment(): Promise<MyDepartment>{
    const httpParams = new HttpParams();
    return this.request.post<MyDepartment>(this.baseUrl + 'getAllMyDepartment', httpParams).then((res) => {
      return res;
    });
  }

  /**
   *
   */
  getAllDepartment(): Promise<any[]>{
    const httpParams = new HttpParams();
    return this.request.post<any[]>(this.baseUrl + 'getAllDepartment', httpParams).then((res) => {
      return res;
    });
  }


  /**
   *
   */
  getAllJobByDept(deptId: string): Promise<any[]>{
    const httpParams = new HttpParams()
      .append('deptId', deptId);
    return this.request.post<any[]>(this.baseUrl + 'getAllJobByDept', httpParams).then((res) => {
      return res;
    });
  }
}
